package com.xh3140.xwidget.app.chart.scales;

import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * 线性刻度列表，相邻两个值之间为等差关系，可看做等差数列
 */
public class LinearAxisScales extends AxisScales {
  private final BigDecimal bigStart;
  private final BigDecimal bigInterval;

  public LinearAxisScales(float start, float interval, int count, int index, int scale) {
    super(start, interval, count, index, scale);
    bigStart = BigDecimal.valueOf(start);
    bigInterval = BigDecimal.valueOf(interval);
  }

  @Override
  public float getValue(int index) {
    return new BigDecimal(index)
            .multiply(bigInterval)
            .add(bigStart).floatValue();
  }

  @Override
  public String getText(int index) {
    return new BigDecimal(index)
            .multiply(bigInterval)
            .add(bigStart)
            .setScale(scale, RoundingMode.HALF_EVEN)
            .toPlainString();
  }
}


